﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.ApplicationServer.Caching;

namespace AppFabricAdministrator
{
    public static class CacheHelper
    {
        static DataCacheFactory cacheFactory;

        public static DataCacheFactory CacheFactory
        {
            get {

                if (cacheFactory == null)
                    CacheInitialize();
                return cacheFactory;
            }
        }
        private static void CacheInitialize()
        {
            DataCacheFactoryConfiguration config=new DataCacheFactoryConfiguration();
            cacheFactory = new DataCacheFactory(config);
        }

        public static DataCache GetNamedCache(string namedCacheName)
        {
            return CacheFactory.GetCache(namedCacheName);
        }

        public static void Clear(this DataCache cache)
        {
            var regions=cache.GetSystemRegions();
            foreach(var region in regions)
            {
                cache.ClearRegion(region);
            }
        }
    }
}
